﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Data.SqlClient;

public partial class Public_Restaurant : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PreRender += new EventHandler(InitPage);
        }
    }

    protected void InitPage(object sender, EventArgs e)
    {
        InitData();
    }
    protected void OnCategoryDishesDataBound(object sender, EventArgs e)
    {
        DataList categoryDishList = (DataList)(sender);
        SqlDataReader reader = ((SqlDataReader)categoryDishList.DataSource);
    }
    protected void InitData()
    {
        MasterPages_ConsumerMaster master = (MasterPages_ConsumerMaster)Page.Master;
        master.DisableFilter();

        Int16 restaurantId = 0;
        Entities.Restaurant restaurant = null;

        String queryString = Request.QueryString["restaurant_id"];
        if (Int16.TryParse(queryString, out restaurantId))
            restaurant = BLL.Command.GetRestaurant(restaurantId);
        if (null == restaurant)
            return;

        name_label.Text = restaurant.Name;
        adver_label.Text = restaurant.Advertise;
        phone_label.Text = restaurant.Mobile + " " + restaurant.Tel;
        address_label.Text = restaurant.Address.Description;
        open_time_label.Text = "外送时间:" + restaurant.Begin + "=>" + restaurant.End;
        delivery_policy_label.Text = restaurant.Delivery.Description;

        String serverAreaText = "外送范围: ";
        if (null != restaurant.ServedDistricts)
        {
            for (int i = restaurant.ServedDistricts.Count - 1; i >= 0; --i)
            {
                serverAreaText += restaurant.ServedDistricts[i].Name + "; ";
            }
            server_areas.Text = serverAreaText;
        }

        comment_summary_hyperlink.NavigateUrl = "~/public/restaurant-restaurant_id=" + restaurant.Id + "-score_id=" + restaurant.ScoreId + ".aspx";

        category_datalist.DataSource = restaurant.Menu.Categories;
        category_datalist.DataBind();
    }

}
